# -*- coding: utf-8 -*-
import scrapy

from ArticleSpider.items import StockArticleItem

#股票列表
class StockSpider(scrapy.Spider):
    name = 'stock'
    allowed_domains = ['quote.eastmoney.com']
    #start_urls = ['http://q.10jqka.com.cn/index/index/board/all/field/zdf/order/desc/page/1/ajax/2/']
    start_urls = ['http://quote.eastmoney.com/stocklist.html']

    def parse(self, response):

        # 实例化item
        stock_item = StockArticleItem()
        # 筛选数据
        titles = response.css('#quotesearch ul li a::text').extract()
        for title in titles:
            titlist = title.split('(')  # 转成列表
            code = titlist[0]
            name = titlist[1][0:-1]  # 去掉最后的括号
            #print(code + '-' + name)
            stock_item['code'] = code
            stock_item['name'] = name
            yield stock_item  # 提交数据 https://blog.csdn.net/heheyanyanjun/article/details/79199378

        pass
